%-----------
% defining the variables and parameters
% -----------
close all;
var y pai r rr z g epsr ym paim rm;

varexo etaz etag etar;

parameters
beta paistar rstar tau kappa phii phipai phiy old_ylead old_ylag old_rpai
new_ylead new_ylag new_rpai
rhoz rhog rhor
lambda elas mu teta corinov gammap gammac;

 
% -----------
% setting the parameter values
% -----------





%  
% parameters
%            prior mean post. mean conf. interval prior pstdev
%  
%       lambda   0.300   0.2060  0.1479  0.2636 beta  0.1000
%       gammac   0.500   0.3842  0.2630  0.5109 beta  0.2000
%         elas   3.000   3.0741  2.2908  3.8679 gamm  0.5000
%       phipai   1.500   1.6303  1.3075  1.9353 gamm  0.2000
%         phii   0.500   0.6640  0.5589  0.7651 beta  0.2000
%         phiy   0.250   0.3329  0.1562  0.5046 gamm  0.1500
%      paistar   4.000   3.2522  2.6498  3.8757 gamm  2.0000
%        rstar   2.000   2.4446  1.8969  2.9671 gamm  1.0000
%         rhog   0.700   0.8278  0.7767  0.8808 beta  0.1000
%         rhoz   0.700   0.6274  0.5187  0.7420 beta  0.1000
%  
% standard deviation of shocks
%            prior mean post. mean conf. interval prior pstdev
%  
%         etag   0.380   0.2143  0.1464  0.2809 invg  0.2000
%         etaz   1.000   0.8313  0.6681  0.9947 invg  0.5200
%         etar   0.310   0.1482  0.1300  0.1680 invg  0.1600
%  
% correlation of shocks
%            prior mean post. mean conf. interval prior pstdev
%  
%    etag,etaz   0.000   0.9108  0.8558  0.9674 norm  0.4000





%Steady State Values
lambda=0.2060;
elas=3.0741;
teta=0.75;
rstar=2.4446;
beta=(1+rstar/100)^(-1/4);
paistar=3.2522;
mu=0.2;
gammap=0.5;
gammac=0.3842;
%Policy Parameters
phii=0.6640;
phipai=1.6303;
phiy=0.3329;

%AR(1)
rhog=0.8313;
rhoz=0.6274;

%Standard errors
sdz=0.8408;
sdg=0.2143;
sdr=0.1482;
corinov=0.9108;


% -----------

model(linear);

y=((1-(lambda*elas/((1-lambda)*(1+mu)))*(1+gammac*mu/(1+elas*(1-gammac))))
/(1+gammac-(lambda*elas/((1-lambda)*(1+mu)))*(1+(gammac*(1+2*mu))/(1+elas*(1-gammac)))))*y(+1)
+((gammac*(1-lambda*elas/((1-lambda)*(1+elas*(1-gammac)))))
/(1+gammac-(lambda*elas/((1-lambda)*(1+mu)))*(1+(gammac*(1+2*mu))/(1+elas*(1-gammac)))))*y(-1)
-((1-gammac)/(1+gammac-(lambda*elas/((1-lambda)*(1+mu)))*(1+(gammac*(1+2*mu))/(1+elas*(1-gammac)))))*(r-pai(+1))+g;

pai=(gammap/(1+(1+rstar/100)^(-1/4)*gammap))*pai(-1)
+((1+rstar/100)^(-1/4)/(1+(1+rstar/100)^(-1/4)*gammap))*pai(+1)+
((1-teta)*(1-(1+rstar/100)^(-1/4)*teta)/teta)*((1/(1-gammac))+(elas/(1+mu)))*(y-z)
-((1-teta)*(1-(1+rstar/100)^(-1/4)*teta)/teta)*(gammac/(1-gammac))*(y(-1));


r=phii*r(-1)+(1-phii)*(phipai*pai(+1)+phiy*y)+epsr;

z=rhoz*z(-1)+etaz;

g=rhog*g(-1)+etag;

epsr=etar;

ym=y;

rr=r-pai;

paim=paistar+4*pai;

rm=rstar+paistar+4*r;

end;

  


steady;

check;
shocks;
var etag = sdg^2;
var etaz = sdz^2;
var etar = sdr^2;
var etag,etaz = (corinov*sdz*sdg);
end;

periods=1000000;
stoch_simul(order=1,irf=0,simul);

